/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.teotigraphix.dx.patterns.manager
{

import flash.events.IEventDispatcher;

import org.teotigraphix.dx.core.ToolKitUtil;
import org.teotigraphix.dx.interfaces.IComponentModel;
import org.teotigraphix.dx.interfaces.IComponentModelCore;
import org.teotigraphix.dx.interfaces.ICoreModelAware;
import org.teotigraphix.dx.interfaces.IModelLayer;
import org.teotigraphix.dx.interfaces.IModelLayerAware;
import org.teotigraphix.dx.interfaces.IModelManager;
import org.teotigraphix.dx.patterns.manager.model.ModelManagerImpl;

/**
 * The static <code>IModelManager</code> interface.
 * 
 * @copyright Teoti Graphix, LLC
 * @author Michael Schmalle
 * @date 07-07-09
 */
public class ModelManager
{
	include '../../core/Version.as'
	
	//--------------------------------------------------------------------------
	//
	//  IToolKitModelManager API :: Methods
	//
	//--------------------------------------------------------------------------
	
	// TODO (mschmalle) Implement removeModelLayer(component)
	
	//----------------------------------
	//  Layers
	//----------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#createModelLayer()
	 */
	public static function createModelLayer(
		client:IEventDispatcher):IModelLayer
	{
		return impl.createModelLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#getModelLayer()
	 */
	public static function getModelLayer(
		client:IEventDispatcher):IModelLayer
	{
		return impl.getModelLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#hasModelLayer()
	 */
	public static function hasModelLayer(
		client:IEventDispatcher):Boolean
	{
		return impl.hasModelLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#registerModelAPI()
	 */
	public static function registerModelAPI(
		api:Class, clazz:Class):void
	{
		impl.registerModelAPI(api, clazz);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#createModel()
	 */
	public static function createModel(
		client:IEventDispatcher, api:Class):IComponentModel
	{
		return impl.createModel(client, api);
	}	
	
	//----------------------------------
	//  Models
	//----------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#registerModel()
	 */
	public static function registerModel(
		client:IEventDispatcher, api:Class, model:IComponentModel):void
	{
		impl.registerModel(client, api, model);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#removeModel()
	 */
	public static function removeModel(
		client:IEventDispatcher, api:Class):IComponentModel
	{
		return impl.removeModel(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#hasModel()
	 */
	public static function hasModel(
		client:IEventDispatcher, api:Class):Boolean
	{
		return impl.hasModel(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#getModel()
	 */
	public static function getModel(
		client:IEventDispatcher, api:Class):IComponentModel
	{
		return impl.getModel(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#getModels()
	 */
	public static function getModels(
		client:IEventDispatcher):Array
	{
		return impl.getModels(client);
	}
	
	//----------------------------------
	//  API
	//----------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#deactivate()
	 */
	public static function activate(host:IModelLayerAware, layer:IModelLayer):void
	{
		impl.activate(host, layer);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#deactivate()
	 */
	public static function deactivate(host:IModelLayerAware, layer:IModelLayer):void
	{
		impl.deactivate(host, layer);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#activateCoreModel()
	 */
	public static function activateCoreModel(
		host:ICoreModelAware, model:IComponentModelCore):void
	{
		impl.activateCoreModel(host, model);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IModelManager#deactivateCoreModel()
	 */
	public static function deactivateCoreModel(
		host:ICoreModelAware, model:IComponentModelCore):void
	{
		impl.deactivateCoreModel(host, model);
	}	
		
	//--------------------------------------------------------------------------
	//
	//  Private Class :: Variables
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	private static var implClassDependency:ModelManagerImpl;
	
	/**
	 * @private
	 */
	dx_internal static var _impl:IModelManager;
	
	/**
	 * Returns the singleton implementation.
	 */
	private static function get impl():IModelManager
	{
		if (!dx_internal::_impl)
		{
			dx_internal::_impl = IModelManager(ToolKitUtil.getSingleton(
				"org.teotigraphix.dx.interfaces::IModelManager"));
		}
		return dx_internal::_impl;
	}	
}
}